package SQL;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLOutput;
import java.sql.Statement;
import java.util.Scanner;

/**
 * 更改用户信息
 */
public class Update {
    public static void main(String[] args) throws SQLException {
        Connection connection=SQL_Collection.Collection();

        //4.执行 SQL 的对象 Statement 执行sql的对象
        Statement statement = connection.createStatement();

        Scanner scanner = new Scanner(System.in);
        System.out.println("选择你要修改的信息：");
        System.out.println("1 : 姓名");
        System.out.println("2 : 学号");
        System.out.println("3 : 性别");
        System.out.println("4 : 电话");
        System.out.println("5 : 出生日期");
        System.out.println("6 : 籍贯");
        System.out.println("7 : 邮箱");
       int t=scanner.nextInt();
        String sql = new String();
        switch (t){
            case 1:
                System.out.println("输入修改后的信息：");
                sql="UPDATE `freshman` SET `NAME`='" +scanner.next()+ "' WHERE `NAME`=''" ;break;
            case 2:
                System.out.println("输入修改后的信息：");
                sql="UPDATE `freshman` SET `ID`='" +scanner.next()+ "' WHERE `ID`=''" ;break;
            case 3:
                System.out.println("输入修改后的信息：");
                sql="UPDATE `freshman` SET `SEX`='" +scanner.next()+ "' WHERE `SEX`=''" ;break;
            case 4:
                System.out.println("输入修改后的信息：");
                sql="UPDATE `freshman` SET `TEL`='" +scanner.next()+ "' WHERE `TEL`=''" ;break;
            case 5:
                System.out.println("输入修改后的信息：");
                sql="UPDATE `freshman` SET `BIRTH`='" +scanner.next()+ "' WHERE `BIRTH`=''" ;break;
            case 6:
                System.out.println("输入修改后的信息：");
                sql="UPDATE `freshman` SET `ADDRESS`='" +scanner.next()+ "' WHERE `ADDRESS`=''" ;break;
            case 7:
                System.out.println("输入修改后的信息：");
                sql="UPDATE `freshman` SET `EMAIL`='" +scanner.next()+ "' WHERE `EMAIL`=''" ;break;
        }

        //5.执行 SQL 的对象 去 执行 SQL ，可能存在结果，查看返回结果
        Statement st = connection.createStatement();
        st.executeUpdate(sql);
    }
}
